<template>
	<view>
		<uni-calendar :lunar="true" :showMonth="true" @change="change" @monthSwitch="monthSwitch" @initdate="initdate" />
		<view class="ym-sel-schedule-now margin-top-20">
			<view class="common no-border-bottom">
				{{changedate}}
			</view>
			<uni-swipe-action>
				<uni-swipe-action-item v-for="(item,index) in scheduleList" :options="options" :key="index" @click="removeDetils(item,index)">
					<view class="uni-list-cell uni-list-cell-last" hover-class="uni-list-cell-hover" @click.stop="scheduleplan(item)">
						<view class="uni-item-cell-left">
							<view class=" font-size24 color-9A9A9A">{{item.F_StartTime}}</view>
							<view class="font-size24 color-9A9A9A">{{item.F_EndTime}}</view>
						</view>
						<view class="cell-navigate">
							<view class="uni-item-right">
								<view class="uni-item-left-name font-size30 color-3A3A3A">{{item.F_Content}}</view>
							</view>
						</view>
					</view>
				</uni-swipe-action-item>
			</uni-swipe-action>
		</view>
		<uni-fab :pattern="pattern" :horizontal="horizontal" :vertical="vertical" :direction="direction" @creqateopen="creqateopen"></uni-fab>
	</view>
</template>

<script>
	import uniCalendar from '@/components/uni-calendar/uni-calendar.vue'
	import uniSwipeAction from '@/components/uni-swipe-action/uni-swipe-action.vue'
	import uniSwipeActionItem from '@/components/uni-swipe-action-item/uni-swipe-action-item.vue'
	import uniFab from '@/components/uni-fab/uni-fab.vue'
	import helper from '@/common/js/helper.js'
	export default {
		components: {
			uniCalendar,
			uniFab,
			uniSwipeAction,
			uniSwipeActionItem
		},
		data() {
			return {
				horizontal: 'right',
				vertical: 'bottom',
				direction: 'horizontal',
				pattern: {
					color: '#7A7E83',
					backgroundColor: '#fff',
					selectedColor: '#007AFF',
					buttonColor: "#007AFF"
				},
				changedate: '',
				scheduleList: [],
				exhibitionList: [],
				startDate: '',
				endDate: '',
				options: [{
					text: '删除',
					style: {
						backgroundColor: '#dd524d'
					}
				}],
			}
		},
		onLoad(e) {
			// console.log(e)
			/* 动态修改标题 */
			let title = uni.getStorageSync("title");
			uni.setNavigationBarTitle({
				title:title.F_FullName
			});
		},
		methods: {
			change(e) {
				// console.log(e);
				let lunar = e.lunar;
				this.changedate = '农历  ' + lunar.IMonthCn + lunar.IDayCn;
				this.scheduleList.splice(0);
				helper.ajax({
					url: '/api/Extend/Schedule/AppList',
					data: {
						startTime: this.startDate,
						endTime: this.endDate,
						dateTime: e.fulldate
					},
					success: res => {
						let todayList = res.data.data.todayList;
						for (let i = 0; i < todayList.length; i++) {
							this.scheduleList.push({
								F_Id: todayList[i].id,
								F_Content: todayList[i].content,
								F_Colour: todayList[i].colour,
								F_ColourCss: todayList[i].colourCss,
								F_EndTime: helper.toDate(todayList[i].endTime, 'yyyy-MM-dd'),
								F_StartTime: helper.toDate(todayList[i].startTime, 'yyyy-MM-dd'),
								F_Early: todayList[i].early,
								dateTime: helper.toDate(todayList[i].endTime, 'yyyy-MM-dd'),
								EndTime: helper.toDate(todayList[i].endTime, 'yyyy-MM-dd') == this.changedate ? '全天' : '结束',
								StartTime: helper.toDate(todayList[i].startTime, 'yyyy-MM-dd') == this.changedate ? '全天' : '开始',
							})
						}
					}
				});
			},
			monthSwitch(e) {
				// console.log(e);
			},
			creqateopen() {
				uni.navigateTo({
					url: './form'
				})
			},
			initdate(cale, nowDate) {
				let canlender = cale.canlender;
				let weeks = cale.weeks;
				let startTime = this.startDate = canlender[0].lunar.cYear + '-' + canlender[0].lunar.cMonth + '-' + canlender[0].lunar
					.cDay;
				let endTime = this.endDate = canlender[canlender.length - 1].lunar.cYear + '-' + canlender[canlender.length - 1].lunar
					.cMonth + '-' + canlender[canlender.length - 1].lunar.cDay;
				for (let i = 0; i < canlender.length; i++) {
					if (canlender[i].fullDate === nowDate.fullDate) {
						this.changedate = '农历  ' + canlender[i].lunar.IMonthCn + canlender[i].lunar.IDayCn;
						break;
					}
				}
				this.scheduleList.splice(0);
				helper.ajax({
					url: '/api/Extend/Schedule/AppList',
					data: {
						startTime: startTime,
						endTime: endTime,
					},
					success: res => {
						let signList = res.data.data.signList;
						let todayList = res.data.data.todayList;
						for (let i = 0; i < 6; i++) {
							for (let j = 0; j < weeks[i].length; j++) {
								let date = helper.toDate(weeks[i][j].lunar.cYear + '-' + weeks[i][j].lunar.cMonth + '-' + weeks[i][j].lunar
									.cDay, 'yyyyMMdd');
								weeks[i][j].isSign = signList[date] == 0 ? false : true;
							}
						}
						for (let i = 0; i < todayList.length; i++) {
							this.scheduleList.push({
								F_Id: todayList[i].id,
								F_Content: todayList[i].content,
								F_Colour: todayList[i].colour,
								F_ColourCss: todayList[i].colourCss,
								F_EndTime: helper.toDate(todayList[i].endTime, 'yyyy-MM-dd'),
								F_StartTime: helper.toDate(todayList[i].startTime, 'yyyy-MM-dd'),
								F_Early: todayList[i].early,
								dateTime: helper.toDate(todayList[i].endTime, 'yyyy-MM-dd'),
								EndTime: helper.toDate(todayList[i].endTime, 'yyyy-MM-dd') == this.changedate ? '全天' : '结束',
								StartTime: helper.toDate(todayList[i].startTime, 'yyyy-MM-dd') == this.changedate ? '全天' : '开始',
							})
						}
					}
				});
			},
			removeDetils(item, index) {
				helper.ajax({
					url: '/api/Extend/Schedule/' + item.F_Id,
					method: 'Delete',
					success: res => {
						this.scheduleList.splice(index, 1);
						uni.redirectTo({
							url: 'index',
						});
						helper.msg(res.data.msg, 'success');;
					}
				});
			},
			scheduleplan(e) {
				uni.navigateTo({
					url: './form?id=' + e.F_Id
				})
			}
		}
	}
</script>

<style>
	page {
		background-color: #f0f2f6;
	}

	.ym-sel-schedule-now {
		background: #FFFFFF;
	}

	.uni-list-cell {
		width: 100%;
	}
</style>
